﻿using System;
using System.ComponentModel;
using Wizard.UI;

namespace TestWizard
{
    public partial class UserNamePage : InternalWizardPage
    {
        private readonly CreateUserContext _context;

        public UserNamePage(CreateUserContext context)
        {
            _context = context;
            InitializeComponent();
        }

        private void UserNamePage_SetActive(object sender, CancelEventArgs e)
        {
            EnableControls();
       }

        private void EnableControls()
        {
            bool nextEnabled = true;

            if (string.IsNullOrEmpty(userNameTextBox.Text))
                nextEnabled = false;
            if (string.IsNullOrEmpty(fullNameTextBox.Text))
                nextEnabled = false;

            if (nextEnabled)
                SetWizardButtons(WizardButtons.Back | WizardButtons.Next);
            else
                SetWizardButtons(WizardButtons.Back);
        }

        private void userNameTextBox_TextChanged(object sender, EventArgs e)
        {
            EnableControls();
        }

        private void fullNameTextBox_TextChanged(object sender, EventArgs e)
        {
            EnableControls();
        }

        private void UserNamePage_WizardNext(object sender, WizardPageEventArgs e)
        {
            _context.UserName = userNameTextBox.Text;
            _context.FullName = fullNameTextBox.Text;
            _context.Description = descriptionTextBox.Text;
        }
    }
}
